package template;

import Resources.sResources;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.InputMap;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.KeyStroke;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Rabid
 */
public abstract class DefaultRegistrationForm extends javax.swing.JInternalFrame {

    /**
     * Creates new form DefaultObjectCreator
     */
    public DefaultRegistrationForm() {
        initComponents();
        initOthers();
    }

    public abstract RegistrantionPanel objectCreator();

    public abstract Object initObject(RegistrantionPanel panel);

    protected abstract String setFrameTitle();

    private List getIdentityComponents(RegistrantionPanel panel) {
        return panel.getIdentityComponent();
    }

    ;
    
    private List getEssentialComponents(RegistrantionPanel panel) {
        return panel.getEsentialComponent();
    }

    ;
    
    protected abstract void getAutoFillComponents(RegistrantionPanel panel);

    private List getOtherComponents(RegistrantionPanel panel) {
        return panel.getOtherComponent();
    }

    

    protected abstract String getViewDataList();

    protected void save() {
        boolean b = SERDefaultRegistrationForm.save(initObject(registrationPanel));
        if (b) {
            doNew();
        }
    }
    
    public void view(ArrayList<Object> list, int index) {
        registrationPanel.bindComponents(list, index);
    }

    private void setToolbarIcon() {
        cmdFirst.setIcon(sResources.getIcon(sResources.MENUBAR_FIRST));
        cmdPrev.setIcon(sResources.getIcon(sResources.MENUBAR_PRIVERS));
        cmdRefresh.setIcon(sResources.getIcon(sResources.MENUBAR_REFRESH));
        cmdNext.setIcon(sResources.getIcon(sResources.MENUBAR_NEXT));
        cmdLast.setIcon(sResources.getIcon(sResources.MENUBAR_LAST));
        cmdFind.setIcon(sResources.getIcon(sResources.MENUBAR_FIND));
        cmdNew.setIcon(sResources.getIcon(sResources.MENUBAR_NEW));
        cmdEdit.setIcon(sResources.getIcon(sResources.MENUBAR_EDIT));
        cmdDelete.setIcon(sResources.getIcon(sResources.MENUBAR_DELETE));
        cmdView.setIcon(sResources.getIcon(sResources.MENUBAR_PREVIEW));
        cmdSave.setIcon(sResources.getIcon(sResources.MENUBAR_SAVE));
        cmdReport.setIcon(sResources.getIcon(sResources.MENUBAR_REPORT));
        cmdExit.setIcon(sResources.getIcon(sResources.MENUBAR_EXIT));
    }

    private void doView() {
        setEnableAll(false);
        setMode(NEW_STATUS);
        objects = SERDefaultRegistrationForm.view(getViewDataList());
        if (!objects.isEmpty()) {
            indexNo = 0;
            maxIndex = objects.size() - 1;
            view(objects, indexNo);
        } else {
            JOptionPane.showMessageDialog(null, "There is no data..!");
        }
        this.setFocusable(true);
    }

    private void doNew() {
        setMode(DEFAULT_STATUS);
        resetValue();
    }

    private void doEdit() {
        setMode(DEFAULT_STATUS);
    }

    private boolean checkRequeredField() {
        return registrationPanel.checkRequeredComponent();
    }

    private void setEnableAll(boolean b) {
        List<Component> i = getIdentityComponents(registrationPanel);
        for (Component component : i) {
            component.setEnabled(b);
        }

        List<Component> c = getEssentialComponents(registrationPanel);
        for (Component component : c) {
            component.setEnabled(b);
        }

        List<Component> c1 = getOtherComponents(registrationPanel);
        for (Component component : c1) {
            component.setEnabled(b);
        }
    }

    private void resetValue() {
        registrationPanel.resetValue();
    }

    private void setMode(int state) {
        switch (state) {
            case DEFAULT_STATUS:
                setEnableAll(true);
                cmdFirst.setEnabled(!true);
                cmdLast.setEnabled(!true);
                cmdNext.setEnabled(!true);
                cmdPrev.setEnabled(!true);
                cmdRefresh.setEnabled(!true);
                cmdFind.setEnabled(!true);
                cmdNew.setEnabled(!true);
                cmdEdit.setEnabled(!true);
                cmdDelete.setEnabled(!true);
                cmdView.setEnabled(true);
                cmdSave.setEnabled(true);
                cmdReport.setEnabled(!true);

                break;
            case NEW_STATUS:
                setEnableAll(!true);
                cmdFirst.setEnabled(true);
                cmdLast.setEnabled(true);
                cmdNext.setEnabled(true);
                cmdPrev.setEnabled(true);
                cmdRefresh.setEnabled(true);
                cmdFind.setEnabled(true);
                cmdNew.setEnabled(true);
                cmdEdit.setEnabled(true);
                cmdDelete.setEnabled(true);
                cmdView.setEnabled(!true);
                cmdSave.setEnabled(!true);
                cmdReport.setEnabled(true);
                break;
        }
    }

    private void setKeyEvents() {
        String mapKey = "UP";
        InputMap inputMap = cmdFirst.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("UP"), mapKey);

        cmdFirst.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdFirstActionPerformed(evt);
            }
        });

        mapKey = "LEFT";
        inputMap = cmdPrev.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("LEFT"), mapKey);

        cmdPrev.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdPrevActionPerformed(evt);
            }
        });

        mapKey = "RIGHT";
        inputMap = cmdNext.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("RIGHT"), mapKey);

        cmdNext.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdNextActionPerformed(evt);
            }
        });

        mapKey = "DOWN";
        inputMap = cmdLast.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("DOWN"), mapKey);

        cmdLast.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdLastActionPerformed(evt);
            }
        });

        mapKey = "KEY_F5";
        inputMap = cmdRefresh.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("F5"), mapKey);

        cmdFind.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdFindActionPerformed(evt);
            }
        });

        mapKey = "KEY_F3";
        inputMap = cmdFind.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("F3"), mapKey);

        cmdFind.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdFindActionPerformed(evt);
            }
        });

        mapKey = "KEY_F4";
        inputMap = cmdNew.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("F4"), mapKey);

        cmdNew.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdNewActionPerformed(evt);
            }
        });
        mapKey = "KEY_F6";
        inputMap = cmdEdit.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("F6"), mapKey);

        cmdEdit.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdEditActionPerformed(evt);
            }
        });
        mapKey = "KEY_F7";
        inputMap = cmdDelete.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("F7"), mapKey);

        cmdDelete.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdDeleteActionPerformed(evt);
            }
        });
        mapKey = "KEY_F8";
        inputMap = cmdView.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("F8"), mapKey);

        cmdView.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdViewActionPerformed(evt);
            }
        });

        mapKey = "KEY_F10";
        inputMap = cmdSave.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("F10"), mapKey);

        cmdSave.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdSaveActionPerformed(evt);
            }
        });

        mapKey = "KEY_F11";
        inputMap = cmdReport.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("F11"), mapKey);

        cmdReport.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdReportActionPerformed(evt);
            }
        });

        mapKey = "KEY_F12";
        inputMap = cmdExit.getInputMap(DefaultRegistrationForm.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(KeyStroke.getKeyStroke("F12"), mapKey);

        cmdExit.getActionMap().put(mapKey, new AbstractAction() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdExitActionPerformed(evt);
            }
        });
    }

    private void setAcctionListner() {
        cmdFirst.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdFirstActionPerformed(evt);
            }
        });

        cmdPrev.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdPrevActionPerformed(evt);
            }
        });

        cmdNext.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdNextActionPerformed(evt);
            }
        });

        cmdLast.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdLastActionPerformed(evt);
            }
        });

        cmdRefresh.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdRefreshActionPerformed(evt);
            }
        });

        cmdFind.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdFindActionPerformed(evt);
            }
        });

        cmdNew.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdNewActionPerformed(evt);
            }
        });

        cmdEdit.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdEditActionPerformed(evt);
            }
        });

        cmdDelete.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdDeleteActionPerformed(evt);
            }
        });

        cmdView.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdViewActionPerformed(evt);
            }
        });

        cmdSave.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdSaveActionPerformed(evt);
            }
        });

        cmdReport.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdReportActionPerformed(evt);
            }
        });
    }

    private void grabFocusList() {
        List<Component> list = registrationPanel.componentList();
        Component component;
        Component cc = this.getFocusOwner();
        int i = 0;
        for (Component c : list) {
            i++;
            if (c == cc) {
                break;
            }
        }

        if (i < list.size() && list != null) {

            component = list.get(i);

            if (component.getClass() == javax.swing.JTextField.class) {
                ((JTextField) component).grabFocus();

            } else if (component.getClass() == javax.swing.JComboBox.class) {
                ((JComboBox) component).grabFocus();

            } else if (component.getClass() == javax.swing.JFormattedTextField.class) {
                ((JFormattedTextField) component).grabFocus();

            } else if (component.getClass() == javax.swing.JCheckBox.class) {
                ((JCheckBox) component).grabFocus();

            } else if (component.getClass() == javax.swing.JPasswordField.class) {
                ((JPasswordField) component).grabFocus();

            } else if (component.getClass() == javax.swing.JRadioButton.class) {
                ((JRadioButton) component).grabFocus();

            }
        }
    }

    private void inputComponentActionListner() {
        List<Component> list = registrationPanel.componentList();
        for (Component component : list) {
            if (component.getClass() == javax.swing.JTextField.class) {
                ((JTextField) component).addActionListener(new java.awt.event.ActionListener() {
                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        grabFocusList();
                    }
                });

            } else if (component.getClass() == javax.swing.JComboBox.class) {
                ((JComboBox) component).addActionListener(new java.awt.event.ActionListener() {
                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        grabFocusList();
                    }
                });
            } else if (component.getClass() == javax.swing.JFormattedTextField.class) {
                ((JFormattedTextField) component).addActionListener(new java.awt.event.ActionListener() {
                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        grabFocusList();
                    }
                });
            } else if (component.getClass() == javax.swing.JCheckBox.class) {
                ((JCheckBox) component).addActionListener(new java.awt.event.ActionListener() {
                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        grabFocusList();
                    }
                });
            } else if (component.getClass() == javax.swing.JPasswordField.class) {
                ((JPasswordField) component).addActionListener(new java.awt.event.ActionListener() {
                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        grabFocusList();
                    }
                });
            } else if (component.getClass() == javax.swing.JRadioButton.class) {
                ((JRadioButton) component).addActionListener(new java.awt.event.ActionListener() {
                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        grabFocusList();
                    }
                });
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    private void initOthers() {

        setKeyEvents();
        setAcctionListner();

        this.setTitle(setFrameTitle());

        setToolbarIcon();

        registrationPanel = objectCreator();
        pnlObjectCreator.add(registrationPanel);
        int width = this.getWidth();
        int height = this.getHeight();

        if (width < registrationPanel.getWidth()) {
            this.setBounds(0, 0, registrationPanel.getWidth() + 50, height + registrationPanel.getHeight() + 5);
        } else {
            this.setBounds(0, 0, width, height + registrationPanel.getHeight() + 5);
        }
        objects = new ArrayList<>();

        doNew();

        inputComponentActionListner();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        cmdFirst = new javax.swing.JButton();
        cmdPrev = new javax.swing.JButton();
        cmdRefresh = new javax.swing.JButton();
        cmdNext = new javax.swing.JButton();
        cmdLast = new javax.swing.JButton();
        cmdFind = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        cmdNew = new javax.swing.JButton();
        cmdEdit = new javax.swing.JButton();
        cmdDelete = new javax.swing.JButton();
        cmdView = new javax.swing.JButton();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        cmdSave = new javax.swing.JButton();
        cmdReport = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        cmdExit = new javax.swing.JButton();
        pnlObjectCreator = new javax.swing.JPanel();

        setClosable(true);
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jToolBar1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jToolBar1.setFloatable(false);

        cmdFirst.setToolTipText("First (Up Key)");
        cmdFirst.setAlignmentX(0.5F);
        cmdFirst.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdFirst.setFocusable(false);
        cmdFirst.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdFirst.setIconTextGap(5);
        cmdFirst.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdFirst);

        cmdPrev.setToolTipText("Previous (Left Key)");
        cmdPrev.setAlignmentX(0.5F);
        cmdPrev.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdPrev.setFocusable(false);
        cmdPrev.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdPrev.setIconTextGap(5);
        cmdPrev.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdPrev);

        cmdRefresh.setToolTipText("Refresh (F5)");
        cmdRefresh.setAlignmentX(0.5F);
        cmdRefresh.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdRefresh.setFocusable(false);
        cmdRefresh.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdRefresh.setIconTextGap(5);
        cmdRefresh.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdRefresh);

        cmdNext.setToolTipText("Next (Right Key)");
        cmdNext.setAlignmentX(0.5F);
        cmdNext.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdNext.setFocusable(false);
        cmdNext.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdNext.setIconTextGap(5);
        cmdNext.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdNext);

        cmdLast.setToolTipText("Last (Down Key)");
        cmdLast.setAlignmentX(0.5F);
        cmdLast.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdLast.setFocusable(false);
        cmdLast.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdLast.setIconTextGap(5);
        cmdLast.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdLast);

        cmdFind.setToolTipText("Find (F3)");
        cmdFind.setAlignmentX(0.5F);
        cmdFind.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdFind.setFocusable(false);
        cmdFind.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdFind.setIconTextGap(5);
        cmdFind.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdFind);
        jToolBar1.add(jSeparator1);

        cmdNew.setToolTipText("Add New (F4)");
        cmdNew.setAlignmentX(0.5F);
        cmdNew.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdNew.setFocusable(false);
        cmdNew.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdNew.setIconTextGap(5);
        cmdNew.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdNew);

        cmdEdit.setToolTipText("Modify (F6)");
        cmdEdit.setAlignmentX(0.5F);
        cmdEdit.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdEdit.setFocusable(false);
        cmdEdit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdEdit.setIconTextGap(5);
        cmdEdit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdEdit);

        cmdDelete.setToolTipText("Delete (F7)");
        cmdDelete.setAlignmentX(0.5F);
        cmdDelete.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdDelete.setFocusable(false);
        cmdDelete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdDelete.setIconTextGap(5);
        cmdDelete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdDelete);

        cmdView.setToolTipText("View (F8)");
        cmdView.setAlignmentX(0.5F);
        cmdView.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdView.setFocusable(false);
        cmdView.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdView.setIconTextGap(5);
        cmdView.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdView);
        jToolBar1.add(jSeparator5);

        cmdSave.setToolTipText("Save (F10)");
        cmdSave.setAlignmentX(0.5F);
        cmdSave.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdSave.setFocusable(false);
        cmdSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdSave.setIconTextGap(5);
        cmdSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdSave);

        cmdReport.setToolTipText("Report (F11)");
        cmdReport.setAlignmentX(0.5F);
        cmdReport.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdReport.setFocusable(false);
        cmdReport.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdReport.setIconTextGap(5);
        cmdReport.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(cmdReport);
        jToolBar1.add(jSeparator3);

        cmdExit.setToolTipText("Exit (F12)");
        cmdExit.setAlignmentX(0.5F);
        cmdExit.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cmdExit.setFocusable(false);
        cmdExit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cmdExit.setIconTextGap(5);
        cmdExit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cmdExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdExitActionPerformed(evt);
            }
        });
        jToolBar1.add(cmdExit);

        pnlObjectCreator.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647));
        pnlObjectCreator.setLayout(new javax.swing.BoxLayout(pnlObjectCreator, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE)
            .addComponent(pnlObjectCreator, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlObjectCreator, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(2, 2, 2))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExitActionPerformed
        this.dispose();
    }//GEN-LAST:event_cmdExitActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        int width = this.getWidth();
        int height = this.getHeight();
        if (width < registrationPanel.getWidth() + 5) {
            width = registrationPanel.getWidth() + 5;
        }
        this.setBounds(0, 0, width, height + registrationPanel.getHeight());
    }//GEN-LAST:event_formInternalFrameOpened

    private void cmdFirstActionPerformed(java.awt.event.ActionEvent evt) {
        if (indexNo != 0) {
            indexNo = 0;
            view(objects, indexNo);
        }
    }

    private void cmdPrevActionPerformed(java.awt.event.ActionEvent evt) {
        if (indexNo > 0) {
            indexNo = indexNo - 1;
            view(objects, indexNo);
        }
    }

    private void cmdNextActionPerformed(java.awt.event.ActionEvent evt) {
        if (indexNo < maxIndex) {
            indexNo = indexNo + 1;
            view(objects, indexNo);
        }
    }

    private void cmdLastActionPerformed(java.awt.event.ActionEvent evt) {
        if (indexNo < maxIndex) {
            indexNo = maxIndex;
            view(objects, indexNo);
        }
    }

    private void cmdFindActionPerformed(java.awt.event.ActionEvent evt) {
    }

    private void cmdRefreshActionPerformed(java.awt.event.ActionEvent evt) {
        doView();
    }

    private void cmdNewActionPerformed(java.awt.event.ActionEvent evt) {
        doNew();
    }

    private void cmdEditActionPerformed(java.awt.event.ActionEvent evt) {
        doEdit();
    }

    private void cmdDeleteActionPerformed(java.awt.event.ActionEvent evt) {
        this.dispose();
    }

    private void cmdViewActionPerformed(java.awt.event.ActionEvent evt) {
        doView();
    }

    private void cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {
        if (checkRequeredField()) {
            save();
        }
    }

    private void cmdReportActionPerformed(java.awt.event.ActionEvent evt) {
        this.dispose();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdDelete;
    private javax.swing.JButton cmdEdit;
    private javax.swing.JButton cmdExit;
    private javax.swing.JButton cmdFind;
    private javax.swing.JButton cmdFirst;
    private javax.swing.JButton cmdLast;
    private javax.swing.JButton cmdNew;
    private javax.swing.JButton cmdNext;
    private javax.swing.JButton cmdPrev;
    private javax.swing.JButton cmdRefresh;
    private javax.swing.JButton cmdReport;
    private javax.swing.JButton cmdSave;
    private javax.swing.JButton cmdView;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JPanel pnlObjectCreator;
    // End of variables declaration//GEN-END:variables
    private RegistrantionPanel registrationPanel;
    private static final int DEFAULT_STATUS = 0;
    private static final int NEW_STATUS = 1;
    private static ArrayList<Object> objects;
    private static int indexNo = 0;
    private static int maxIndex = 0;

}
